import { createApp } from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store"; 
import './assets/css/reset.css'
import './assets/css/vant-custom.less'
import 'vant/lib/index.css';

import { 
  Button,
  Tab, 
  Tabs,
  List,
  Picker,
  Popup,
  Field,
  DatePicker,
  ConfigProvider,
  Toast,
  PullRefresh,
  Uploader,
  Calendar,
  Icon
} from 'vant';

const app = createApp(App);

app
.use(Button)
.use(Tabs)
.use(Tab)
.use(List)
.use(Picker)
.use(Popup)
.use(Field)
.use(DatePicker)
.use(ConfigProvider)
.use(Toast)
.use(PullRefresh)
.use(Uploader)
.use(Calendar)
.use(Icon);
const globalEvent = new class {
  constructor() {
    this.listeners = {};
  }

  on(event, callback) {
    if (!this.listeners[event]) {
      this.listeners[event] = [];
    }
    this.listeners[event].push(callback);
  }

  emit(event, data) {
    if (this.listeners[event]) {
      this.listeners[event].forEach(callback => {
        callback(data);
      });
    }
  }
}();

app.config.globalProperties.$myGlobalEvent = globalEvent;



app.use(store).use(router).mount("#app");

export { globalEvent };